<template>
  <div>
    <HeaderPage />
    <SearchHeader></SearchHeader>
    <navPage></navPage>
    <div class="box">
      <div class="title">竞价权限申请</div>
      <div class="form">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="公司名称" prop="companyName">
            <el-input
              v-model="ruleForm.companyName"
              placeholder="请输入公司名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="银行卡号" prop="bankCard">
            <el-input
              v-model="ruleForm.bankCard"
              placeholder="请输入银行卡号"
            ></el-input>
          </el-form-item>
          <el-form-item label="开户行" prop="openingBank">
            <el-input
              v-model="ruleForm.openingBank"
              placeholder="请输入开户行"
            ></el-input>
          </el-form-item>
          <el-form-item label="开户人姓名" prop="openingMan">
            <el-input
              v-model="ruleForm.openingMan"
              placeholder="请输入开户人姓名"
            ></el-input>
          </el-form-item>
          <el-form-item label="手机号" prop="phone">
            <el-input
              v-model="ruleForm.phone"
              placeholder="请输入注册时手机号"
            ></el-input>
          </el-form-item>
          <el-row>
            <el-col :span="12">
              <el-form-item label="身份证正面" prop="idcardFront">
                <upload
                  :img="ruleForm.idcardFront"
                  @update="updateCardFront"
                  :uploadURL="cardUpUrl"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证反面" prop="idcardReverse">
                <upload
                  :img="ruleForm.idcardReverse"
                  :uploadURL="cardUpUrl"
                  @update="updateCardreverse"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
              >提交申请</el-button>
               <el-button  @click="$router.go(-1)"
              >返回上一页</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <FooterPage></FooterPage>
  </div>
</template>
<script>
import HeaderPage from "../../components/head";
import SearchHeader from "../indexHome/searchHeader";
import FooterPage from "../../components/footer";
import navPage from "../../components/nav";
import { phone, brankCard } from "../../plugins/validate";
import upload from "../../components/upLoad/index";
export default {
  components: {
    HeaderPage,
    SearchHeader,
    FooterPage,
    navPage,
    upload
  },
  data() {
    var phoneValidate = (rule, value, callback) => {
      phone(rule, value, callback);
    };

    var bankCardValidate = (rule, value, callback) => {
      brankCard(rule, value, callback);
    };
    return {
      cardUpUrl: this.baseUrl + "/sys/file/uploadIdCard",
      ruleForm: {
        bankCard: "",
        companyName: "",
        idcardFront: "",
        idcardReverse: "",
        openingBank: "",
        openingMan: "",
        phone: ""
      },
      rules: {
        bankCard: [
          {
            validator: bankCardValidate,
            required: true,
            message: "请输入银行卡号",
            trigger: "change"
          }
        ],

        phone: [{ validator: phoneValidate, required: true, trigger: "blur" }],
        companyName: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
          { min: 3, max: 60, message: "长度在 3 到 60 个字符", trigger: "blur" }
        ],
        idcardFront: [
          { required: true, message: "请上传身份证号正面", trigger: "change" }
        ],
        idcardReverse: [
          { required: true, message: "请上传身份证号反面", trigger: "change" }
        ],
        openingBank: [
          { required: true, message: "请请输入开户行", trigger: "blur" },
          { min: 3, max: 60, message: "长度在 3 到 60 个字符", trigger: "blur" }
        ],
        openingMan: [
          { required: true, message: "请请输入开户人姓名", trigger: "blur" },
          { min: 2, max: 5, message: "长度在 2 到 60 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$http(
            "post",
            "/sys/iaBidding/add.do",
            this.ruleForm,'json'
          ).then(res => {
              if (res.code =='0000') {
                  this.$message({
                      type:'success',
                      message:'操作成功'
                  })
                  this.$router.go(-1)
              }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 身份证正面
    updateCardFront(img) {
      this.ruleForm.idcardFront = img;
    },
    // 身份证反面
    updateCardreverse(img) {
      this.ruleForm.idcardReverse = img;
    }
  }
};
</script>
<style scoped>
.box {
  width: 1200px;
  margin: 5px auto;
  min-height: 400px;
  background: #fff;
}
.title {
  text-align: center;
  line-height: 70px;
  font-size: 16px;
  font-weight: 600;
}
.form {
  width: 500px;
  margin: 20px auto;
}
</style>
<style>
.form .el-input__inner {
  background: #f6f6f6;
  width: 400px;
}
.form .el-input__icon {
  color: #ee781b;
}
.form .el-form-item__label {
  color: #272727;
}
.form .el-button--primary {
  width: 160px;
  height: 38px;
  background: #ee781b;
  border-radius: 2px;
  border: 0;
  margin-top: 20px;
  margin-bottom: 30px;
}
.form .el-button--default {
      width: 160px;
  height: 38px;
  background: #fff;
  border-radius: 2px;
  border: 0;
  margin-top: 20px;
  margin-bottom: 30px;
  border:1px solid #ee781b;
  color: #ee781b;
}
.form .el-button--default:hover {
    background: #ee781b;
    color: #fff;
}
</style>